﻿using System;
using System.Windows.Forms;

namespace uTILLIty.ChartBuilder.Designer
{
	public partial class ChartDesigner : Form
	{

		public ChartDesigner()
		{
			InitializeComponent();
		}

		private ChartDesignerController _controller;
		public ChartDesignerController Controller
		{
			get { return _controller; }
			set
			{
				_controller = value;
				_controller.Initialize(this, openFileDialog, saveFileDialog, chart, configBindingSource, statusBar);
			}
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			Controller.CreateNewChartConfiguration();
			properties.SelectedObject = chart;
		}

		private void ExitToolStripMenuItemClick(object sender, EventArgs e)
		{
			Controller.ExitApplication();
		}

		private void NewToolStripMenuItemClick(object sender, EventArgs e)
		{
			Controller.CreateNewChartConfiguration();
		}

		private void OpenToolStripMenuItemClick(object sender, EventArgs e)
		{
			Controller.OpenExistingConfiguration();
		}

		private void SaveToolStripMenuItemClick(object sender, EventArgs e)
		{
			Controller.SaveConfiguration(false);
		}

		private void SaveAsToolStripMenuItemClick(object sender, EventArgs e)
		{
			Controller.SaveConfiguration(true);
		}

		private void AboutToolStripMenuItemClick(object sender, EventArgs e)
		{
			Controller.ShowAboutDialog();
		}

		private void LoadDataButtonClick(object sender, EventArgs e)
		{
			Controller.ReloadDataSource();
		}

		private void ConfigChanged(object sender, EventArgs e)
		{
			Controller.ReassignChartDimensionsFromConfig();
		}

		private void EditConnectionStringClick(object sender, EventArgs e)
		{
			Controller.BuildConnectionString();
		}
	}
}
